﻿using System;
using System.Collections.Generic;
using System.Drawing;

using OpenTK;
using OpenTK.Graphics.OpenGL;

namespace AnimatingHair.Entity
{
    class HairParticle : SPHParticle
    {
        public double Area { get; set; }
        public Vector3d Direction;

        public Vector3d RootDirection;
        public double U;
        public double V;
        public double S;

        public double DistanceFromCamera;

        public bool IsRoot { get { return S < 0; } }

        public List<HairParticle> Neighbors = new List<HairParticle>();
        public List<HairParticle> NeighborsRoot = new List<HairParticle>();
        public List<HairParticle> NeighborsTip = new List<HairParticle>();

        public Hair hair;

        public int ID;

        public HairParticle( Hair hair, int id )
        {
            this.hair = hair;

            ID = id;

            Velocity = Vector3d.Zero;
        }

        public HairParticle( Hair hair, int id, double u, double v, double s )
        {
            this.hair = hair;

            ID = id;

            U = u;
            V = v;
            S = s;

            fromUVS( u, v, s );

            Velocity = Vector3d.Zero;
            RootDirection = -Vector3d.UnitY;
            Direction = RootDirection;
        }

        private void fromUVS( double u, double v, double s )
        {
            Position.X = 3 * u;
            Position.Y = -3 * s;
            Position.Z = 3 * v;
        }

        public override string ToString()
        {
            return ID.ToString();
        }

        public override void IntegrateForce( double timeStep )
        {
            if ( !IsRoot )
            {
                base.IntegrateForce( timeStep );
            }
        }

        internal override void RKStep( int stepNumber )
        {
            if (!IsRoot)
                base.RKStep( stepNumber );
        }
    }
}
